<%@page import="study.itwill.team5.admin.AdminItem"%>
<%@page import="study.itwill.jsp.WebHandler"%>
<%@page import="study.itwill.team5.board.Comment"%>
<%@page import="study.itwill.team5.board.CommentItem"%>
<%@page import="study.itwill.common.DBHandler"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%@ include file="../session.jsp"%>
<%@ include file="../dbcon.jsp"%>
<%

	int comment_seq = web.getInt("comment_seq");

	if (comment_seq == -1) {
		db.disconnect();
		web.goPage(null, "파라미터가 잘못되었습니다.");
		return;
	}
%>
<%
	// 덧글목록 받아오기
	Comment comment = new Comment();
	CommentItem item = comment.viewComment(comment_seq);
	
	if (item == null) {
		db.disconnect();
		web.goPage(null, "데이터 조회에 실패했습니다. 잠시후 다시 시도해 주세요.");
		return;
	}
%>
<!DOCTYPE html>
<html lang="ko">
<head>
<%@ include file="../head.jsp"%>
</head>
<body>
	<div class="container">
		<form id="frmCommentEdit" class="form-horizontal" role="form"
			method="post" action="editCommentOk.jsp">
			<input type="hidden" name="comment_seq" value="<%=item.getSeq()%>">
			<input type="hidden" name="board_seq"
				value="<%=item.getBoard_seq()%>"> <input type="hidden"
				name="member_seq" value="<%=item.getMember_seq()%>">
			<fieldset>
				<div class="form-group">
					<label for="member" class="col-md-2 control-label">작성자</label>
					<div class="col-md-10">
						<p class="form-control-static"><%=item.getUser_name()%></p>
					</div>
				</div>

				<div class="form-group">
					<label for="comment" class="col-md-2 control-label">내용</label>
					<div class="col-md-10">
						<textarea class="form-control" rows="3" id="comment"
							name="comment"><%=item.getComment().replace("<br />", "\n")%></textarea>
					</div>
				</div>

				<div class="form-group">
					<div class="col-md-offset-2 col-md-10">
						<div class="row">
							<div class="col-md-6">
								<button type="submit" class="btn btn-primary btn-block">수정하기</button>
							</div>
							<div class="col-md-6">
								<button type="reset" class="btn btn-warning btn-block">다시작성</button>
							</div>
						</div>

					</div>
				</div>
			</fieldset>
		</form>
	</div>

	<% db.disconnect(); %>
	<script src="/Team-Project/assets/js/jquery.js"></script>
	<script src="/Team-Project/assets/js/bootstrap.min.js"></script>
	<script src="/Team-Project/assets/js/string.js"></script>
	<script type="text/javascript">
		$(function() {
			$("#frmCommentEdit").submit(function() {
				
				// 덧글 입력여부 검사
				if (!$("textarea[name='comment']").val().isValue()) {
					alert("덧글을 입력하세요.");
					$("input[name='comment']").focus();
					return false;
				}
			});
		});
	</script>

</body>
</html>